package com.haohan.stock.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.haohan.stock.domain.BaseArea;
import com.haohan.stock.service.BaseAreaService;
import com.haohan.stock.vo.MysqlPage;
import com.haohan.stock.vo.ReturnType;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

@Api(description="区域维护")
@RestController
@RequestMapping("/basearea")
public class BaseAreaController {
	
	@Autowired
	private BaseAreaService baseAreaService;
	
	@RequestMapping(value = "/save", method = RequestMethod.POST)
	@ApiOperation(value = "保存或更新区域信息", httpMethod = "POST", response = ResponseEntity.class)
	public ResponseEntity<ReturnType<BaseArea>> save(
			@ApiParam(required = true, name = "paramData", value = "主体") @RequestBody BaseArea baseArea,
			@RequestHeader("token") String token) throws Exception {
		ReturnType<BaseArea> basedocReturnType = new ReturnType<BaseArea>();
		basedocReturnType.setFlag(0);
		basedocReturnType.setDesc("");
		basedocReturnType.setData(baseAreaService.save(baseArea));
		return new ResponseEntity<ReturnType<BaseArea>>(basedocReturnType, HttpStatus.OK);
	}
	
	@RequestMapping(value = "/delete", method = RequestMethod.POST)
	@ApiOperation(value = "删除区域信息", httpMethod = "POST", response = ResponseEntity.class)
	public ResponseEntity<ReturnType<BaseArea>> delete(
			@ApiParam(required = true, name = "paramData", value = "主体") @RequestBody BaseArea baseArea,
			@RequestHeader("token") String token) throws Exception {
		ReturnType<BaseArea> basedocReturnType = new ReturnType<BaseArea>();
		basedocReturnType.setFlag(0);
		basedocReturnType.setDesc("");
		basedocReturnType.setData(baseAreaService.delete(baseArea));
		return new ResponseEntity<ReturnType<BaseArea>>(basedocReturnType, HttpStatus.OK);
	}
	
	@RequestMapping(value = "/get", method = RequestMethod.POST)
	@ApiOperation(value = "获取单个区域信息", httpMethod = "POST", response = ResponseEntity.class)
	public ResponseEntity<ReturnType<BaseArea>> get(
			@ApiParam(required = true, name = "paramData", value = "主体") @RequestBody BaseArea baseArea,
			@RequestHeader("token") String token) throws Exception {
		ReturnType<BaseArea> basedocReturnType = new ReturnType<BaseArea>();
		basedocReturnType.setFlag(0);
		basedocReturnType.setDesc("");
		basedocReturnType.setData(baseAreaService.get(baseArea));
		return new ResponseEntity<ReturnType<BaseArea>>(basedocReturnType, HttpStatus.OK);
	}
	
	@RequestMapping(value = "/page", method = RequestMethod.POST)
	@ApiOperation(value = "获取分页区域信息", httpMethod = "POST", response = ResponseEntity.class)
	public ResponseEntity<ReturnType<MysqlPage<BaseArea>>> getPage(
			@ApiParam(required = true, name = "paramData", value = "主体") @RequestBody MysqlPage<BaseArea> mysqlPage,
			@RequestHeader("token") String token) throws Exception {
		ReturnType<MysqlPage<BaseArea>> basedocReturnType = new ReturnType<MysqlPage<BaseArea>>();
		basedocReturnType.setFlag(0);
		basedocReturnType.setDesc("");
		basedocReturnType.setData(baseAreaService.getMysqlPage(mysqlPage));
		return new ResponseEntity<ReturnType<MysqlPage<BaseArea>>>(basedocReturnType, HttpStatus.OK);
	}
	
	@RequestMapping(value = "/list", method = RequestMethod.POST)
	@ApiOperation(value = "获取所有!", httpMethod = "POST", response = ResponseEntity.class)
	public ResponseEntity<ReturnType<List<BaseArea>>> getList(
			@ApiParam(required = false, name = "paramData", value = "主体") @RequestBody BaseArea baseArea,
			@RequestHeader("token") String token) throws Exception {
		ReturnType<List<BaseArea>> basedocReturnType = new ReturnType<List<BaseArea>>();
		basedocReturnType.setFlag(0);
		basedocReturnType.setDesc("");
		basedocReturnType.setData(baseAreaService.getList(baseArea));
		return new ResponseEntity<ReturnType<List<BaseArea>>>(basedocReturnType, HttpStatus.OK);
	}
}
